package com.itheima.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Slf4j
/**
 * 切入点表达式
 * execution(访问修饰符? 返回值类型 包名.类名.?方法名(参数类型) throws 异常)
 */
//@Aspect
//@Component
public class DemoAspect2 {
    //要求给list方法和getById方法添加通知
    @Pointcut("execution(* com..DeptServiceImpl.list(..)) || execution(* com..DeptServiceImpl.getById(..))")
    public void pt(){}

    @Before("@annotation(com.itheima.aspect.Log)")
    public void before(JoinPoint joinPoint){
        //1.获取目标类名
        String name = joinPoint.getTarget().getClass().getName();
        log.info("name--------{}",name);
        //2.获取目标方法签名
        Signature signature = joinPoint.getSignature();
        log.info("signature------{}",signature);
        //3获取目标方法名
        String name1 = signature.getName();
        log.info("name1--------{}",name1);
        //4.获取方法参数
        Object[] args = joinPoint.getArgs();
        log.info("args---{}", Arrays.toString(args));


        System.out.println("-----前置通知------");

    }
}
